<include file="Public/min-header"/>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <section class="content">
        <!-- Main content -->
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 修改店铺信息</h3>
                </div>
                <div class="panel-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_tongyong" data-toggle="tab">店铺信息</a></li>
                        <li><a href="#tab_goods_images" data-toggle="tab">店铺营业执照信息</a></li>
                        <li><a href="#tab_shop" data-toggle="tab">店铺装修</a></li>
                        <li><a href="#postsetting" data-toggle="tab">运费设置</a></li>

                    </ul>
                    <!--表单数据-->
                    <form method="post" action="{:U('Shop/shop_update')}" id="addEditBrandForm" enctype="multipart/form-data" onsubmit="return checkName();">
                        
                        <!--通用信息-->
                        <div class="tab-content">
                            <div class="tab-pane active" id="tab_tongyong">

                                <table class="table table-bordered">
                                    <tbody>
                                    <tr>
                                        <td>店铺名称:</td>
                                        <td>
                                            <input type="text" value="{$shop_data['shop_name']}" name="shop_name" class="form-control" style="width:200px;"/>
                                            <input type="hidden" name="ids" value="{$shop_data['id']}"/>
                                            <span id="err_name" style="color:#F00; display:none;">店铺名称不能为空</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>店铺用户名:</td>
                                        <td>
                                            <input type="text" value="{$shop_data['shop_user']}" name="shop_user" class="form-control" style="width:200px;" placeholder="50"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>店铺联系方式:</td>
                                        <td>
                                            <input type="text" value="{$shop_data['shop_tel']}" name="shop_tel" class="form-control" style="width:200px;" placeholder="50"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>店铺头像:</td>
                                        <td>
                                            <img src="{$shop_data['shop_head_img']}" alt="" width="100xp" height="100px"/>
                                            <input type="file" name="shop_head_img" class="form-control" style="width:200px;"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>店铺背景图:</td>
                                        <td>
                                            <img src="{$shop_data['shop_bei_img']}" alt="" width="100xp" height="100px"/>
                                            <input type="file" name="shop_bei_img" class="form-control" style="width:200px;"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>店铺所在省市:</td>
                                        <td>
                                            <input type="text" value="{$shop_data['shop_address_city']}" name="shop_address_city" class="form-control" style="width:200px;"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>店铺所在街道:</td>
                                        <td>
                                            <input type="text" value="{$shop_data['shop_address_street']}" name="shop_address_street" class="form-control" style="width:200px;"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>店铺简介:</td>
                                        <td>
                                            <textarea name="shop_intro"  id="" cols="30" rows="10">{$shop_data['shop_intro']}</textarea>
                                            <!--<input type="text"  name="shop_address_street" class="form-control" style="width:200px;"/>-->
                                        </td>
                                    </tr>
                                             </tbody>
                                        </table>
                                    </div>
                                    <div class="tab-pane" id="tab_goods_images">
                                        <table class="table table-bordered">
                                            <tbody>
                                                <tr>
                                                    <td>营业执照名称:</td>
                                                    <td>
                                                        <input type="text" value="{$shop_data['license_name']}" name="license_name" class="form-control" style="width:200px;"/>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>营业执照图片:</td>
                                                    <td>
                                                        <img src="{$shop_data['license_img']}" alt="" width="100xp" height="100px"/>
                                                        <input type="file" name="license_img" class="form-control" style="width:200px;"/>
                                                    </td>
                                                 </tr>
                                                <tr>
                                                    <td>营业所在省市:</td>
                                                    <td>
                                                        <input type="text" value="{$shop_data['license_address_city']}" name="license_address_city" class="form-control" style="width:200px;"/>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>营业所在街道:</td>
                                                    <td>
                                                        <input type="text" value="{$shop_data['license_address_street']}" name="license_address_street" class="form-control" style="width:200px;"/>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="tab-pane" id="tab_shop">
                                        <table class="table table-bordered">
                                            <tbody>
                                                <tr>  
                                                <td>店铺轮播图：</td>                               
                                                <td>  
                                                <foreach name="ShopImages" item="vo" key="k" >
                                                    <div style="width:100px; text-align:center; margin: 5px; display:inline-block;" class="goods_xc">
                                                        <input type="hidden" value="{$vo['image_url']}" name="shop_images[]">
                                                        <a onclick="" href="{$vo['image_url']}" target="_blank"><img width="100" height="100" src="{$vo['image_url']}"></a>
                                                        <br>
                                                        <a href="javascript:void(0)" onclick="ClearPicArr2(this,'{$vo['image_url']}')">删除</a>
                                                    </div>
                                                </foreach>
                                                
                                                    <div class="goods_xc" style="width:100px; text-align:center; margin: 5px; display:inline-block;">
                                                        <input type="hidden" name="shop_images[]" value="" />
                                                        <a href="javascript:void(0);" onclick="GetUploadify(10,'','goods','call_back2');"><img src="/Public/images/add-button.jpg" width="100" height="100" /></a>
                                                        <br/>
                                                        <a href="javascript:void(0)">&nbsp;&nbsp;</a>
                                                    </div>                                        
                                                </td>
                                             </tr>           
                                            </tbody>
                                        </table>                                        
                                    </div>

                                    <div class="tab-pane" id="postsetting">
                                        <table class="table table-bordered">
                                            <tbody>
                                                <tr>
                                                    <td>满多少元包邮(整数，0为不设置):</td>
                                                    <td>
                                                        <input type="number" pattern="^\d{1,}$" value="{$shop_data['fee_freepost']}" name="fee_freepost" class="form-control" style="width:200px;"/>元
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>默认邮费【首重费】(0为全部包邮):</td>
                                                    <td>
                                                        <input type="number" value="{$shop_data['default_postfee']}" name="default_postfee" class="form-control" style="width:200px;"/>元
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>首重(单位：g)</td>
                                                    <td>
                                                        <input type="number" value="{$shop_data['first_weight']}" name="first_weight" class="form-control" style="width:200px;"/>g
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>续重(单位：g，为0时只计算首重费):</td>
                                                    <td>
                                                        <input type="number" value="{$shop_data['second_weight']}" name="second_weight" class="form-control" style="width:200px;"/>g
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>续重费(单位：元，为0时只计算首重费):</td>
                                                    <td>
                                                        <input type="number" value="{$shop_data['add_postfee']}" name="add_postfee" class="form-control" style="width:200px;"/>元
                                                    </td>
                                                </tr>

                                            </tbody>
                                        </table>
                                    </div>
                            </div>
                            <div class="pull-right">
                                <input type="hidden" name="id" value="{$brand.id}">
                                <input type="hidden" name="p" value="{$_GET[p]}">
                                <button class="btn btn-primary" data-toggle="tooltip" type="submit" data-original-title="保存">保存</button>
                            </div>
                        </div>

                    </form><!--表单数据-->
                </div>
            </div>
        </div>    <!-- /.content -->
    </section>
</div>
<script>
    // 判断输入框是否为空
    function checkName(){
        var name = $("#addEditBrandForm").find("input[name='shop_name']").val();
        if($.trim(name) == '')
        {
            $("#err_name").show();
            return false;
        }
        return true;
    }

    $(document).ready(function(){
        $(":checkbox[cka]").click(function(){
            var $cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");
            if($(this).is(':checked')){
                $cks.each(function(){$(this).prop("checked",true);});
            }else{
                $cks.each(function(){$(this).removeAttr('checked');});
            }
        });
    });

    function choosebox(o){
        var vt = $(o).is(':checked');
        if(vt){
            $('input[type=checkbox]').prop('checked',vt);
        }else{
            $('input[type=checkbox]').removeAttr('checked');
        }
    }
    /*
     * 以下是图片上传方法
     */
    // 上传商品图片成功回调函数
    function call_back(fileurl_tmp){
        $("#original_img").val(fileurl_tmp);
        $("#original_img2").attr('href', fileurl_tmp);
    }
 
    // 上传商品相册回调函数
    function call_back2(paths){
        
        var  last_div = $(".goods_xc:last").prop("outerHTML");  
        for (i=0;i<paths.length ;i++ )
        {                    
            $(".goods_xc:eq(0)").before(last_div);  // 插入一个 新图片
                $(".goods_xc:eq(0)").find('a:eq(0)').attr('href',paths[i]).attr('onclick','').attr('target', "_blank");// 修改他的链接地址
            $(".goods_xc:eq(0)").find('img').attr('src',paths[i]);// 修改他的图片路径
                $(".goods_xc:eq(0)").find('a:eq(1)').attr('onclick',"ClearPicArr2(this,'"+paths[i]+"')").text('删除');
            $(".goods_xc:eq(0)").find('input').val(paths[i]); // 设置隐藏域 要提交的值
        }              
    }
    /*
     * 上传之后删除组图input     
     * @access   public
     * @val      string  删除的图片input
     */
    function ClearPicArr2(obj,path)
    {
        $(obj).parent().remove();
        return true;
        $.ajax({
            type:'GET',
            url:"{:U('Admin/Uploadify/delupload')}",
            data:{action:"del", filename:path},
            success:function(){
                $(obj).parent().remove(); // 删除完服务器的, 再删除 html上的图片               
            }
        });
        // 删除数据库记录
        $.ajax({
            type:'GET',
            url:"{:U('Admin/Shop/del_goods_images')}",
            data:{filename:path},
            success:function(){
                    //         
            }
        });     
    }
 


/** 以下 商品属性相关 js*/

// 属性输入框的加减事件
function addAttr(a)
{
    var attr = $(a).parent().parent().prop("outerHTML");    
    attr = attr.replace('addAttr','delAttr').replace('+','-');  
    $(a).parent().parent().after(attr);
}
// 属性输入框的加减事件
function delAttr(a)
{
   $(a).parent().parent().remove();
}


</script>
</body>
</html>